<template>
	<view>
		<u-sticky>
			<view class="header">
				<u-search placeholder="请输入会员ID" v-model="keyword" shape="square" :showAction="false" @search="searchlist"></u-search>
				<!-- <view class="button">
					<view class="btn" @click="show = true">{{ categoryName }}</view>
				</view> -->
			</view>
			<!-- <u-picker :show="show" :columns="categoryList" keyName="categoryName" @confirm="confirm" @cancel="show = false"></u-picker> -->
			<view class="tags"><u-tabs :list="list1" @click="click" width="300rpx"></u-tabs></view>
		</u-sticky>
		<view class="content">
				<view class="box" v-for="item in memberList">
					<view class="box-top">
						<view class="box-two">
							<image style="width: 150rpx;height: 150rpx;" :src="item.headImg" mode=""></image>
							<view class="tuijian">{{item.id}}</view>
						</view>
						
						<view class="box-three">
							<view class="one" style="display: flex;align-items: center;justify-content: space-between;width: 100%;">
								<view class="">
									{{ item.userName }}
								</view>
							<view class="" style="color: firebrick;" @click="goPath(item.id)">
								消费记录
							</view>
							</view>
							<view class="two">
								最后登录时间：{{ item.lastLoginTime }}
							</view>
						</view>
					</view>
					<view class="box-bottom">
						<view class="con" @click="updata(item)">
							<view class="con-one">
								￥{{item.balance}}
							</view>
							<view class="con-two">
								余额
							</view>
						</view>
						<view class="con" @click="updata1(item)">
							<view class="con-one">
								{{item.integral}}
							</view>
							<view class="con-two">
								积分
							</view>
						</view>
						<view class="con">
							<view class="con-one" v-if="item.userState==0">
								正常
							</view>
							<view class="con-one" v-if="item.userState==1">
								禁用
							</view>
							<view class="con-two">
								状态
							</view>
						</view>
						<view class="con">
							<view class="con-one" v-if="item.nembershipLevelId==0">
								非会员
							</view>
							<view class="con-one" v-if="item.nembershipLevelId==1">
								正式会员
							</view>
							<view class="con-two">
								会员
							</view>
						</view>
					</view>
					
				</view>
		</view>
		<u-modal :show="show" title="修改余额" :showCancelButton="true" @confirm="confirm" @cancel="show = false">
			<view class="slot-content"><u--input placeholder="请输入" border="surround" v-model="form.balance"></u--input></view>
		</u-modal>
		<u-modal :show="show1" title="修改积分" :showCancelButton="true" @confirm="confirm1" @cancel="show1 = false">
			<view class="slot-content"><u--input placeholder="请输入" border="surround" v-model="form.integral"></u--input></view>
		</u-modal>
	</view>
</template>

<script>
import {searchUserInfoList,adminUpdateUserInfo,searchUserInfoById } from '../../../utils/api.js';
export default {
	data() {
		return {
			keyword: '',
			show: false,
			show1: false,
			list1: [
				{
					id:-1,
					name: '全部'
				},
				{
					id:0,
					name: '正常'
				},
				{
					id:1,
					name: '禁用 '
				}
			],

			memberList: [],
			categoryList: [[{ categoryName: '更多分类', id: -1 }]],
			search: {
				page: 1,
				size: 10
			},
			categoryName: '更多分类',
			total:0,
			form:{}
		};
	},
	onShow() {
		// this.getCategoryList();
		this.getMemberList();
	},
	onReachBottom() {
		
		if(this.memberList.length<this.total){
			this.search.page++;
			// this.search.size+=10
			this.getMemberList();
		}
		
	},
	methods: {
		click(item) {
			this.search.page=1;
			this.memberList=[]
			this.getMemberList();
		},
		goPath(id){
			uni.navigateTo({
				url:'/pages/member/consumptionList/consumptionList?keyWord='+id
			})
		},
		searchlist() {
			this.getMemberList();
			this.keyword = '';
		},
		getMemberList() {
			let data = {
				page: this.search.page,
				size: this.search.size,
				adminId: uni.getStorageSync('userInfo').id,
				userServiceToken: uni.getStorageSync('userInfo').userServiceToken,
				keyword: this.keyword,
			};
			searchUserInfoList(data).then(res => {
				if (res.code == 200) {
					if (this.search.page == 1) {
						this.memberList = [];
					}
					let arr = [];
					arr = this.memberList.concat(res.body.list);
					this.memberList = arr;
					this.total=res.body.total
					
				}
			});
		},
		updata(item) {
			this.show = true;
			let data={
				userId:item.id
			}
			searchUserInfoById(data).then(res=>{
				if(res.code==200){
					this.form=res.body
				}
			})
			
					
		},
		updata1(item) {
			this.show1 = true;
			let data={
				userId:item.id
			}
			searchUserInfoById(data).then(res=>{
				if(res.code==200){
					this.form=res.body
				}
			})
		},
		 confirm(e) {
			adminUpdateUserInfo(this.form).then(res=>{
				if(res.code==200){
					uni.showToast({
						icon:'success',
						title:res.msg
					})
					this.show = false;
					this.getMemberList();
				}
			})
		},
		confirm1(e) {
			adminUpdateUserInfo(this.form).then(res=>{
				if(res.code==200){
					uni.showToast({
						icon:'success',
						title:res.msg
					})
					this.show1 = false;
					this.getMemberList();
				}
			})
		},
		// getCategoryList() {
		// 	this.categoryList = [[{ categoryName: '更多分类', id: -1 }]];
		// 	let data = {
		// 		page: this.search.page,
		// 		size: this.search.size,
		// 		adminId: uni.getStorageSync('userInfo').id,
		// 		userServiceToken: uni.getStorageSync('userInfo').userServiceToken,
		// 		id: 141,

		// 		businessId: -1
		// 	};
		// 	searchPlugsGoodCategoryList(data).then(res => {
		// 		if (res.code == 200) {
		// 			// this.categoryList[0]=res.body.list
		// 			res.body.list.forEach(item => {
		// 				this.categoryList[0].push(item);
		// 			});
		// 			console.log(this.categoryList[0], 456465);
		// 		}
		// 	});
		// },
		// confirm(e) {
		// 	console.log(e.value[0].id);
		// 	this.goodsCategoryId = e.value[0].id;
		// 	this.categoryName = e.value[0].categoryName;
		// 	this.show = false;
		// 	this.getMemberList();
		// },
		
		
	}
};
</script>
<style lang="scss">
page {
	background-color: #f5f5f5;
}
</style>
<style lang="scss" scoped>
page {
	background-color: #999;
}
.header {
	display: flex;
	align-items: center;
	padding: 20rpx;
	background-color: #fff;
	.button {
		width: 180rpx;
		height: 60rpx;
		.btn {
			color: #fff;
			height: 60rpx;
			line-height: 60rpx;
			font-size: 26rpx;
			background-color: #6da7ff;
			text-align: center;
		}
	}
}
.tags {
	background-color: #fff;
	/deep/.u-tabs__wrapper__nav__item {
		padding: 0 80rpx;
	}
}
.content {
	padding: 20rpx;
	.box {
		border-radius: 20rpx;
		margin-bottom: 20rpx;
		background-color: #fff;
		padding: 20rpx;
		.box-top{
			display: flex;
			align-items: center;
			padding-bottom: 20rpx;
			border-bottom: 1rpx solid #f5f5f5;
			.box-two {
				// width: 150rpx;
				// height: 150rpx;
				margin-right: 20rpx;
				position: relative;
				border-radius: 10rpx;
				overflow: hidden;
				.tuijian {
					color: #fff;
					background-color: rgba(0, 0, 0, 0.3);
					height: 40rpx;
					width: 100%;
					font-size: 24rpx;
					text-align: center;
					line-height: 40rpx;
					
					position: absolute;
			
					
					left: 0;
					bottom: 0;
				}
				.xiajia{
					width: 150rpx;
					height: 150rpx;
					color: #fff;
					position: absolute;
					left: 0;
					top: 0;
					text-align: center;
					line-height: 150rpx;
				}
			}
			
			.box-three {
				.one {
					font-weight: 700;
				}
				.two {
					margin: 25rpx 0;
					display: flex;
					align-items: center;
					font-size: 26rpx;
					.text {
						font-size: 26rpx;
						width: 150rpx;
					}
				}
				
			}
		}
		.box-bottom{
			display: flex;
			align-items: center;
			justify-content: space-around;
			padding-top: 20rpx;
			.con{
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;
				.con-one{
					
				}
				.con-two{
					font-size: 26rpx;
					color: #999;
				}
			}
		}
		
	}
}
.footer {
	display: flex;
	align-items: center;
	padding: 20rpx;
	position: fixed;
	bottom: 0;
	background-color: #fff;
	width: 100%;
	.left {
		margin-right: 50rpx;
	}
	.right {
		background-color: #eff6ff;
		border: 1rpx solid #d1e5ff;
		// padding: 20rpx;
		border-radius: 30rpx;
		color: #016eff;
		display: flex;
		justify-content: space-between;
		align-items: center;
		.tet {
			padding: 15rpx 30rpx;
			border-right: 1rpx solid #d1e5ff;
		}
		.tet:nth-last-child(1) {
			border-right: none;
		}
	}
}
</style>
